﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

public partial class The_hien_TH_GIOHANG : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Page_PreRender(object sender, EventArgs e)
    {
        tinh_tien();
        tinh_so_sach();
        Label1.Text = double.Parse(Session["So_tien"].ToString()).ToString("#,##0 VND");
        Label2.Text = Convert.ToInt32(Session["So_sach"].ToString()).ToString();
    }

    void tinh_tien()
    {
        //tính tiền
        double so_tien = 0.0;
        ArrayList gio_hang = (ArrayList)Session["Gio_hang"];
        if (gio_hang.Count != 0)
        {
            for (int i = 0; i <= gio_hang.Count - 1; i++)
                so_tien += ((GIO_HANG)gio_hang[i]).Thanh_tien;
            Session["Gio_hang"] = gio_hang;
            Session["So_tien"] = so_tien;
        }
        else
            Session["So_tien"] = 0.0;
    }

    void tinh_so_sach()
    {
        //tính số sách
        int so_luong = 0;
        ArrayList gio_hang = (ArrayList)Session["Gio_hang"];
        if (gio_hang.Count != 0)
        {
            for (int i = 0; i <= gio_hang.Count - 1; i++)
                so_luong += ((GIO_HANG)gio_hang[i]).So_luong;
            Session["Gio_hang"] = gio_hang;
            Session["So_sach"] = so_luong;
        }
        else
            Session["So_sach"] = 0;
    }
}